package org.example;

import java.util.HashSet;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/2/29 20:27
 */
public class ChangHashCode {


    public static void main(String[] args) {
        HashSet set = new HashSet();
        Person p1 = new Person(1001, "AA");
        Person p2 = new Person(1002, "BB");
        
        
        try {
            
        }finally {
            
        }
        
        
        set.add(p1);
        set.add(p2);
        p1.name = "CC";
        set.remove(p1);
        System.out.println(set.size());
    }
    
    
}

class Person{
    int id;
    String name;
    
    public Person(int id, String name){
        this.id = id;
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj){
            return true;    
        }
        if (obj instanceof Person){
            Person person = (Person) obj;
            if (this.name.equals(person.name) && this.id == person.id){
                return true;
            }
        }
        return false;
    }
    
    
    
}
